package com.ctgu.chatapp.view.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.ctgu.chatapp.databinding.ItemMsgboxBinding
import com.ctgu.chatapp.showPojo.FriendMsg

class MsgBoxAdapter(var recordList: List<FriendMsg>, val view: View.OnClickListener) :
    RecyclerView.Adapter<MsgBoxAdapter.MsgBoxViewHolder>() {

    class MsgBoxViewHolder(val binding: ItemMsgboxBinding) :
        RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = run {
        val binding =
            ItemMsgboxBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        binding.patten.setOnClickListener(view)
        MsgBoxViewHolder(binding)
    }

    override fun onBindViewHolder(holder: MsgBoxViewHolder, position: Int) {
        holder.binding.record = recordList[position]
    }

    override fun getItemCount() = recordList.size
}